package com.zhiy.com.estation.ui.fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.zhiy.com.estation.R;
import com.zhiy.com.estation.ui.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Zyh on 2016/12/5.
 */
public class FragmentPerson extends BaseFragment {
    @Override
    protected int getInflaterLayoutId() {
        return R.layout.fra_person;
    }
    @BindView(R.id.fra_person_list)
    ListView mListView;
    private List<String> data;
    @Override
    protected void initView(View view) {
        MyAdapter myAdapter=new MyAdapter();
        data=new ArrayList<>();
        data.add(mPreferen.getName());
        data.add(mPreferen.getEmail());
        data.add(mPreferen.getPhone());
        mListView.setAdapter(myAdapter);
    }
    class MyAdapter extends BaseAdapter{
        @Override
        public int getCount() {
            return data.size();
        }
        @Override
        public String getItem(int i) {
            return data.get(i);
        }
        @Override
        public long getItemId(int i) {
            return i;
        }
        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            if (view==null) {
                view= LayoutInflater.from(mContext).inflate(R.layout.item_fra_person,null);
                holder=new ViewHolder(view);
                view.setTag(holder);
            }else {
                holder= (ViewHolder) view.getTag();
            }
            switch (i){
                case 0:
                    holder.avar.setText("用户名");
                    break;
                case 1:
                    holder.avar.setText("邮箱");
                    break;
                case 2:
                    holder.avar.setText("电话");
                    break;
            }

            holder.msgEt.setText(getItem(i));
            return view;
        }
        ViewHolder holder;
        class ViewHolder{
            TextView avar;
            TextView msgEt;
            public ViewHolder(View view) {
                avar= (TextView) view.findViewById(R.id.avar);
                msgEt= (TextView) view.findViewById(R.id.per_msg);
            }
        }
    }

}
